package com.itheima.test.customer;

public class Foodie extends Thread{
    @Override
    public void run() {
        while(true){
            synchronized(Desk.lock){
                if(Desk.HamburgerNumber == 0){//汉堡包数量为0时退出
                    break;
                }else{
                    if(Desk.flag){//桌子上有汉堡则吃汉堡
                        System.out.println("宅男吃货正在吃汉堡");
                        Desk.HamburgerNumber--;//汉堡数量减一
                        Desk.flag = false;//桌子上汉堡状态为无
                        Desk.lock.notifyAll();//叫醒厨师
                    }else{//桌子上无汉堡则等待
                        try {
                            Desk.lock.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }
}
